package com.dapeis.core.utils;

import java.util.Calendar;
import java.util.Date;
import java.util.regex.Pattern;

import javax.persistence.Transient;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.ag.module.common.api.domain.vo.KVObj;
import com.ag.utils.DictionarySettingUtils;
import com.dapeis.core.utils.RequirementConfig.Type;
import com.dapeis.core.utils.StylistConstants.Coupons.status;

/**
 * 
 * Title:StylistConstants.java StylistConstants Description:
 * 
 * @author yuanyong
 * @date 2017年4月17日 下午4:54:04 Email: hzyuanyong@126.com
 *
 */
public final class StylistConstants {

    /**
     * 存储分隔符
     */
    public final static String SPE_SUX = "|";

    /**
     * 前端返回OPENID
     */
    public final static String FRONT_OPEN_ID_PATAM = "openId";

    public final static Pattern mobilePhonePattern = Pattern
	    .compile("\\d{6,11}");
    /**
     * 需要修改
     */
    public final static String WX_DOMAIN_KEY = "http://potato.ngrok.joinclub.cn";

    /**
     * 异常类型
     *
     */
    public static class Loggers {

	public static Logger EXCEPTION = LoggerFactory.getLogger("exception");

	public static Logger TIMEOUT = LoggerFactory.getLogger("timeout");
    }

    /**
     * 评价类型
     */
    public static class CommentType {
	/**
	 * 订单评价
	 */
	public static final String ORDER = "order";
	/**
	 * 方案评价
	 */
	public static final String PLAN = "plan";
    }

    /**
     * 全局状态
     */
    public static final class State {

	public static final Integer NORMAL = 1;

	public static final Integer DISABLE = 0;
    }

    /**
     * 衣橱类型
     */
    public static final class GarderobeType {
	/**
	 * 用户
	 */
	public static final String USER = "user";
	/**
	 * 搭配师
	 */
	public static final String DPS = "dps";

    }

    /**
     * 第三方来源
     */
    public static final class UserSource {

	public static final Integer WEIXIN = 1;

	public static final Integer QQ = 2;
    }

    public static final class OrderSource {
	public static final String WEIXIN_USER = "wexin_user";
	public static final String DPS_APP_ipad = "dps_app_ipad";
	public static final String DPS_APP_IPHONE = "dps_app_iphone";
    }

    /**
     * 性别数据
     */
    public static final class Sex {

	public static final Integer MAN = 1;

	public static final Integer LADY = 2;
    }

    /**
     * 审核状态 0|未提交,1|待审核,|2审核通过,|3审核不通过
     */
    public static final class Audit {
	/**
	 * 未提交
	 */
	public static final Integer NO_SUBMIT = 0;
	/**
	 * 等待审核
	 */
	public static final Integer WAIT_AUDIT = 1;
	/**
	 * 通过审核
	 */
	public static final Integer PASS_AUDIT = 2;
	/**
	 * 审核不通过
	 */
	public static final Integer REJECT_AUDIT = 3;
    }

    /**
     * 上传服务器类目列表
     */
    public static final class UploadType {

	public static final String HEAD = "head"; // 头像
	public static final String GARDEROBE = "garderobe"; // 衣橱
	public static final String LIFE = "life";// 生活照
	public static final String QRCODE = "qrcode";// 二维码
	public static final String IDCARD = "idcard";// 身份证
	public static final String PLAN = "plan";// 方案主图
    }

    /**
     * 短信通道类型
     *
     */
    public static final class ChannelType {

	public static final class DPS {

	    public static final int APP_LOGIN = 1;
	    public static final int MONEY_OUTLAY = 2;
	}

	public static final class USER {
	    public static final int WECHAT_BING = 50;
	}

    }

    /**
     * 支付渠道
     */
    public static final class PayChannel {
	public static final String WECHANT = "wx";
	public static final String SWIFTPASS = "swiftpass"; // 威富通
    }

    /**
     * 是否点赞
     */
    public static final class Agree {
	public static final Integer NO = 0; // 没有
	public static final Integer YES = 1; // 已赞
    }

    /**
     * 
     * 订单状态
     */
    public static class Order {
	/**
	 * 支付状态
	 */
	public static class PayStatus {
	    /**
	     * 待付款
	     */
	    public static final int WAIT_PAY = 0;
	    /**
	     * 已经付款
	     */
	    public static final int PAY_SUCCESS = 1;
	    /**
	     * 待退款
	     */
	    public static final int WAIT_REFUND = 2;
	    /**
	     * 已经退款
	     */
	    public static final int REFUND = 3;
	}

	/**
	 * 订单状态(需要补充)
	 *
	 */
	public static class Status {
	    /**
	     * 待付款（待支付）
	     */
	    public static final int WAIT_PAY = 0;
	    /**
	     * 付款成功(发布中)
	     */
	    public static final int PAY_SUCCESS = 1;
	    /**
	     * 被抢单(服务中,搭配师抢单成功)
	     */
	    public static final int SERVICE = 2;
	    /**
	     * 待评价（搭配师点击已完成）
	     */
	    public static final int WAIT_COMMENT = 3;
	    /**
	     * 完成(用户端已评价)
	     */
	    public static final int FINISHED = 10;
	    /**
	     * 订单关闭
	     */
	    public static final int COLSED = -1;
	    /**
	     * 取消
	     */
	    public static final int CANEL = -2;
	    /**
	     * 订单删除
	     */
	    public static final int DELETE = -3;
	    /**
	     * 订单申请退款
	     */
	    public static final int REFUND = -4;

	}

	/**
	 * 订单类型
	 */
	public static class Type {
	    /**
	     * 需求支付
	     */
	    public static final String REQUIREMENT = "requirement";
	    /**
	     * 订单打赏(服务打赏,需求未实现)
	     */
	    @Deprecated
	    public static final String AWARD_SERVE = "service_award";
	    /**
	     * 搭配方案打赏
	     */
	    public static final String AWARD_PROGRAM = "program_award";
	}

    }

    /**
     * 退款状态
     */
    public enum RefundStatus {
	SUCCESS, FAIL, PROCESSING, NOTSURE, CHANGE
    }

    /**
     * 数据类型
     */
    public static final class ContentType {
	public static final String TEXT_HTML = "text/html;charset=utf-8";
	public static final String JSON = "application/json";
    }

    public static String getWxDomain() {
	return WX_DOMAIN_KEY;
    }

    public static String getAge(Long _birthday) {
	Date birthDay = new Date(_birthday);
	Calendar cal = Calendar.getInstance();

	if (cal.before(birthDay)) {
	    throw new IllegalArgumentException(
		    "The birthDay is before Now.It's unbelievable!");
	}
	int yearNow = cal.get(Calendar.YEAR);
	int monthNow = cal.get(Calendar.MONTH);
	int dayOfMonthNow = cal.get(Calendar.DAY_OF_MONTH);
	cal.setTime(birthDay);

	int yearBirth = cal.get(Calendar.YEAR);
	int monthBirth = cal.get(Calendar.MONTH);
	int dayOfMonthBirth = cal.get(Calendar.DAY_OF_MONTH);

	int age = yearNow - yearBirth;

	if (monthNow <= monthBirth) {
	    if (monthNow == monthBirth) {
		if (dayOfMonthNow < dayOfMonthBirth)
		    age--;
	    } else {
		age--;
	    }
	}
	return age + "岁";

    }

    /**
     * 拼装图片路径
     * 
     * @param _path
     * @return
     */
    public static final String PASERIMGPATH(String _path) {
	String BaseURL = DictionarySettingUtils.getParameterValueWithDefault(
		"fileService.webUrl",
		"http://stylist2017-1252470632.cossh.myqcloud.com");
	return BaseURL + _path;
    }

    public static final class PlanState {
	/**
	 * 发布中
	 */
	public static final Integer ISSUE = 1;
	/**
	 * 草稿箱
	 */
	public static final Integer SAVE = 0;
    }

    public static final String getOrderStatusStr(com.dapeis.domain.Order order) {
	int status = order.getState();
	if (status == Order.Status.WAIT_PAY)
	    return "待付款";
	if (status == Order.Status.PAY_SUCCESS)
	    return "发布中";
	if (status == Order.Status.SERVICE)
	    return "服务中";
	if (status == Order.Status.WAIT_COMMENT)
	    return "待评价";
	if (status == Order.Status.FINISHED)
	    return "已完成";
	if (status == Order.Status.COLSED)
	    return "已关闭";
	if (status == Order.Status.CANEL)
	    return "已取消";
	if (status == Order.Status.DELETE)
	    return "已删除";
	if (status == Order.Status.REFUND) {
	    if (order.getPayState().intValue() == Order.PayStatus.REFUND) {
		return "退款成功";
	    } else if (order.getPayState().intValue() == Order.PayStatus.WAIT_REFUND) {
		if (null != order.getRefundStatus()) {
		    if (order.getRefundStatus().equalsIgnoreCase("SUCCESS")) {
			return "退款成功";
		    } else if (order.getRefundStatus().equalsIgnoreCase("FAIL")) {
			return "退款失败";
		    } else if (order.getRefundStatus().equalsIgnoreCase(
			    "PROCESSING")) {
			return "退款处理中";
		    }
		}
		return "退款处理中";
	    }
	}

	return "订单状态非法";
    }

    /**
     * 搭配师工作时间
     * 
     * @return
     */
    public static final class WORKTIME {
	public static final Integer FULLTIME = 1; // 全职
	public static final Integer PARTTIME = 2; // 兼职
    }

    /**
     * 收支明细
     */
    public static final class MoneyLog {
	/**
	 * 类型,收入或支出
	 */
	public static final class Type {
	    /**
	     * 收入
	     */
	    public static final String INCOME = "income";
	    /**
	     * 支出
	     */
	    public static final String OUTLAY = "outlay";
	}

	/**
	 * 状态,收入,冻结中,已入账 提现:已提交-->待审核-->提现成功（已入账,审核成功）---或(信息有误)
	 */
	public static final class Status {
	    /**
	     * 冻结
	     */
	    public static final Integer FREEZE = 0;
	    /**
	     * 支出 提交申请(提交成功)
	     */
	    public static final Integer OUTLAY_COMMIT = 1;
	    /**
	     * 支出 审核成功,已转账
	     */
	    public static final Integer OUTLAY_AUDIT_SUCCESS = 2;
	    /**
	     * 提交信息有误
	     */
	    public static final Integer OUTLAY_AUDIT_FAIL = 5;
	    /**
	     * 已入账
	     */
	    public static final Integer RECORDED = 10;
	}

	public static final class Source {
	    /**
	     * 咨询
	     */
	    public static final Integer CONSULTING = 1;
	    /**
	     * 购物
	     */
	    public static final Integer BUY = 2;
	    /**
	     * 逛街
	     */
	    public static final Integer SHOPPING = 3;
	    /**
	     * 整理
	     */
	    public static final Integer FINISHING = 4;
	    /**
	     * 打赏
	     */
	    public static final Integer AWARD = 5;
	    /**
	     * 提现
	     */
	    public static final Integer OUTLAY = 6;
	}
    }

    /**
     * 全局状态
     */
    public static final class IsReply {

	public static final Integer YES = 1;

	public static final Integer NO = 0;
    }

    public static final class Coupons {
	public static final class Type {
	    /**
	     * 兑换获得(只能兑换1次)
	     */
	    public static final String EXCHANGE = "exchange";
	    /**
	     * 用户使用自己的券获得(不限制)
	     */
	    public static final String PROMOTION = "promotion";
	}

	public static final class status {
	    /**
	     * 正常
	     */
	    public static final Integer NORMAL = 1;
	    /**
	     * 已使用
	     */
	    public static final Integer USED = 2;
	    /**
	     * 已过期
	     */
	    public static final Integer EXPIRATION = 3;
	}
    }

    /**
     * 生成验证码
     * 
     * @return
     */
    public static final String getCouponsCode() {
	String element = "3456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	char[] rands = new char[6];
	StringBuffer sbBuffer = new StringBuffer();
	for (int i = 0; i < rands.length; i++) {
	    int rand = (int) (Math.random() * element.length());
	    rands[i] = element.charAt(rand);
	    sbBuffer.append(element.charAt(rand));
	}
	return sbBuffer.toString();
    }

    /**
     * 生成验证码
     * 
     * @return
     */
    public static final Integer getTIMMsgRandom() {
	String element = "123456789";
	char[] rands = new char[6];
	StringBuffer sbBuffer = new StringBuffer();
	for (int i = 0; i < rands.length; i++) {
	    int rand = (int) (Math.random() * element.length());
	    rands[i] = element.charAt(rand);
	    sbBuffer.append(element.charAt(rand));
	}
	return new Integer(sbBuffer.toString());
    }

    public static final String getAuditState(int status) {
	if (status == Audit.NO_SUBMIT)
	    return "未提交";
	if (status == Audit.REJECT_AUDIT)
	    return "未审核";
	if (status == Audit.PASS_AUDIT)
	    return "审核通过";
	if (status == Audit.WAIT_AUDIT)
	    return "待审核";
	return "未知审核状态";
    }

    public static String getSPPayBody(com.dapeis.domain.Order order) {
	String orderType = order.getType();
	if (StylistConstants.Order.Type.REQUIREMENT.equalsIgnoreCase(orderType)) {
	    return "打赏";
	} else if (StylistConstants.Order.Type.AWARD_PROGRAM
		.equalsIgnoreCase(orderType)) {
	    return "发布需求";
	}
	return "Ms搭配师";
    }

    public static boolean checkScoreValue(String score) {
	if (StringUtil.isBlank(score)) {
	    return false;
	}
	// 12345为分值
	return "12345".indexOf(score) >= 0;
    }

    public static boolean checkShopTypeValue(Integer type) {
	if (null == type)
	    return false;
	String _type = type.toString();
	if (StringUtil.isBlank(_type)) {
	    return false;
	}

	// 1234分别对应不同的需求类型
	return "1234".indexOf(_type) >= 0;
    }

     /**
     * 全局状态
     */
    public static final class Job {

	public static final Integer DPS = 0;

	public static final Integer DESIGNER = 1;
	
	public static final Integer SHOPS = 2;

    }

}
